package com.hsgene.goods.condition;

import com.google.common.collect.Lists;
import com.hsgene.common.util.date.SimpleDateUtils;
import com.hsgene.common.util.support.LimitHelper;
import io.jsonwebtoken.lang.Strings;
import org.apache.commons.lang.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

/**
 * 商城商品信息查询条件
 *
 * @author wangbing
 * @version 1.0, 2018/7/25
 */
public class GoodsMallCondition implements Serializable {

    private static final long serialVersionUID = 8904790578125028373L;
    /**
     * 发布时间开始
     */
    private Date timeStart;

    /**
     * 发布时间结束
     */
    private Date timeEnd;

    /**
     * 最低价
     */
    private BigDecimal priceStart;

    /**
     * 最高价
     */
    private BigDecimal priceEnd;

    /**
     * 商品状态
     */
    private Integer status;

    /**
     * 搜索关键字
     */
    private String searchKey;

    /**
     * 搜索关键字-套餐名称（全匹配）
     */
    private String goodsName;

    /**
     * 供应商商品id
     */
    private String goodsId;

    /**
     * 主分类
     */
    private Integer mainCategory;

    /**
     * 子分类
     */
    private Integer subCategory;

    /**
     * 检测类型
     */
    private List<Integer> detectionTypes;

    /**
     * 检测方式
     */
    private List<Integer> detectionModes;

    /**
     * 采样方式
     */
    private List<Integer> sampleModes;

    /**
     * 其它（包邮[1]和促销[2]，多个以英文逗号分隔）
     */
    private String others;

    /**
     * 是否查询商品检测相关信息
     */
    private boolean queryDetection = false;

    /**
     * 包含在内的商品id列表
     */
    private List<String> goodsMallIds;

    /**
     * 页号
     */
    private int page;

    /**
     * 每页大小
     */
    private int size;

    /**
     * 排序参数（默认：createTime，销量：sales，好评：comment，价格：price）
     */
    private String orderBy;

    /**
     * 是否升序（true：升序，false：降序）
     */
    private boolean isAsc;

    public LimitHelper buildLimitHelper() {
        return LimitHelper.create(page, size);
    }

    public LimitHelper buildLimitHelper(boolean isLimitMaxPageSize) {
        return LimitHelper.create(page, size, isLimitMaxPageSize);
    }

    public Integer getMainCategory() {
        return mainCategory;
    }

    public void setMainCategory(Integer mainCategory) {
        this.mainCategory = mainCategory;
    }

    public Integer getSubCategory() {
        return subCategory;
    }

    public void setSubCategory(Integer subCategory) {
        this.subCategory = subCategory;
    }

    public String getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(String goodsId) {
        this.goodsId = goodsId;
    }

    public BigDecimal getPriceStart() {
        return priceStart;
    }

    public void setPriceStart(BigDecimal priceStart) {
        this.priceStart = priceStart;
    }

    public BigDecimal getPriceEnd() {
        return priceEnd;
    }

    public void setPriceEnd(BigDecimal priceEnd) {
        this.priceEnd = priceEnd;
    }

    public String getSearchKey() {
        return searchKey;
    }

    public void setSearchKey(String searchKey) {
        this.searchKey = searchKey;
    }

    public Date getTimeStart() {
        return timeStart;
    }

    public void setTimeStart(Date timeStart) {
        this.timeStart = timeStart;
    }

    public void setTimeStart(String timeStart) {
        Date date = SimpleDateUtils.parseDate(timeStart, SimpleDateUtils.DatePattern.STANDARD_PATTERN.toString());
        this.timeStart = date;
    }

    public Date getTimeEnd() {
        return timeEnd;
    }

    public void setTimeEnd(Date timeEnd) {
        this.timeEnd = timeEnd;
    }

    public void setTimeEnd(String timeEnd) {
        Date date = SimpleDateUtils.parseDate(timeEnd, SimpleDateUtils.DatePattern.STANDARD_PATTERN.toString());
        this.timeEnd = date;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getGoodsName() {
        return goodsName;
    }

    public void setGoodsName(String goodsName) {
        this.goodsName = goodsName;
    }

    public List<Integer> getDetectionTypes() {
        return detectionTypes;
    }

    public void setDetectionTypes(List<Integer> detectionTypes) {
        this.detectionTypes = detectionTypes;
    }

    public void addDetectionType(Integer detectionType) {
        if (detectionType == null) {
            return;
        }
        if (detectionTypes == null) {
            detectionTypes = Lists.newArrayList();
        }
        detectionTypes.add(detectionType);
    }

    public void addDetectionType(String detectionTypes) {
        if (StringUtils.isBlank(detectionTypes)) {
            return;
        }
        if (this.detectionTypes == null) {
            this.detectionTypes = Lists.newArrayList();
        }
        String[] list = Strings.split(detectionTypes, ",");
        for (String s : list) {
            Integer type = Integer.valueOf(s);
            this.detectionTypes.add(type);
        }
    }

    public List<Integer> getDetectionModes() {
        return detectionModes;
    }

    public void setDetectionModes(List<Integer> detectionModes) {
        this.detectionModes = detectionModes;
    }

    public void addDetectionModes(Integer detectionMode) {
        if (detectionMode == null) {
            return;
        }
        if (detectionModes == null) {
            detectionModes = Lists.newArrayList();
        }
        detectionModes.add(detectionMode);
    }

    public void addDetectionModes(String detectionModes) {
        if (StringUtils.isBlank(detectionModes)) {
            return;
        }
        if (this.detectionModes == null) {
            this.detectionModes = Lists.newArrayList();
        }
        String[] list = Strings.split(detectionModes, ",");
        for (String s : list) {
            Integer mode = Integer.valueOf(s);
            this.detectionModes.add(mode);
        }
    }

    public List<Integer> getSampleModes() {
        return sampleModes;
    }

    public void setSampleModes(List<Integer> sampleModes) {
        this.sampleModes = sampleModes;
    }

    public void addSampleMode(Integer sampleMode) {
        if (sampleMode == null) {
            return;
        }
        if (sampleModes == null) {
            sampleModes = Lists.newArrayList();
        }
        sampleModes.add(sampleMode);
    }

    public void addSampleMode(String sampleModes) {
        if (StringUtils.isBlank(sampleModes)) {
            return;
        }
        if (this.sampleModes == null) {
            this.sampleModes = Lists.newArrayList();
        }
        String[] list = Strings.split(sampleModes, ",");
        for (String s : list) {
            Integer mode = Integer.valueOf(s);
            this.sampleModes.add(mode);
        }
    }

    public boolean getQueryDetection() {
        return queryDetection;
    }

    public void setQueryDetection(boolean queryDetection) {
        this.queryDetection = queryDetection;
    }

    public String getOthers() {
        return others;
    }

    public void setOthers(String others) {
        this.others = others;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getSize() {
        return size;
    }

    public void setSize(int size) {
        this.size = size;
    }

    public String getOrderBy() {
        return orderBy;
    }

    public void setOrderBy(String orderBy) {
        this.orderBy = orderBy;
    }

    public boolean getIsAsc() {
        return isAsc;
    }

    public void setIsAsc(boolean asc) {
        isAsc = asc;
    }

    public List<String> getGoodsMallIds() {
        return goodsMallIds;
    }

    public void setGoodsMallIds(List<String> goodsMallIds) {
        this.goodsMallIds = goodsMallIds;
    }
}
